package com.wfh.activity;

import com.wfh.R;
import com.wfh.util.Util;

import android.os.Bundle;
import android.app.ActivityGroup;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;

@SuppressWarnings("deprecation")
public class MainActivity extends ActivityGroup {

	private Intent[] intentArr = new Intent[4];
	private String[] tagArr = new String[] { "home", "order", "interact",
			"setting" };
	private Integer[] strArr = new Integer[] { R.string.main, R.string.order,
			R.string.interact, R.string.more };
	private Integer[] imgArr = new Integer[] { R.drawable.shouye_white,
			R.drawable.diancai_white, R.drawable.hudong_white,
			R.drawable.gengduo_white };
	private Integer[] hoverArr = new Integer[] { R.drawable.homeselector,
			R.drawable.orderselector, R.drawable.interactselector,
			R.drawable.moreselector };
	private TabHost tabhost;
	private int count;// 记录返回键次数
	public static MainActivity group;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		tabhost = (TabHost) findViewById(R.id.tabhost1);

		// 初始化intent
		intentArr[0] = new Intent(this, HomeActivity.class);
		intentArr[1] = new Intent(this, OrderActivity.class);
		intentArr[2] = new Intent(this, InteractActivity.class);
		intentArr[3] = new Intent(this, SettingActivity.class);

		// 设置标签
		tabhost.setup(this.getLocalActivityManager());
		for (int i = 0; i < tagArr.length; i++) {
			View view = (View) LayoutInflater.from(this).inflate(
					R.layout.tabmini, null);
			((TextView) view.findViewById(R.id.tab_label)).setText(strArr[i]);// 设置文字
			((ImageView) view.findViewById(R.id.tab_ico))
					.setImageResource(imgArr[i]);
			tabhost.addTab(tabhost.newTabSpec(tagArr[i])
					.setContent(intentArr[i]).setIndicator(view));
		}

		// 监听标签变化
		tabhost.setOnTabChangedListener(new OnTabChangeListener() {
			@Override
			public void onTabChanged(String tabId) {
				for (int i = 0; i < tagArr.length; i++) {
					if (tabId.equals(tagArr[i])) {
						((ImageView) tabhost.getCurrentTabView().findViewById(
								R.id.tab_ico)).setImageResource(hoverArr[i]);
					}
				}
			}
		});
		tabhost.setCurrentTab(0);
		((ImageView) tabhost.getChildAt(0).findViewById(R.id.tab_ico))
				.setImageResource(hoverArr[0]);

		group = this;

	}

	public void onStart() {
		super.onStart();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

}
